let s:python3_candidates = [
            \   'C:/Users/CXL/.venv/default/Scripts/python.exe',
            \   'C:/Programs/Python/3.12-x64/python.exe',
            \   'D:/Programs/Python/3.12x64/python.exe',
            \   'C:/Programs/Python/3.10.32/python.exe'
            \ ]

function! bootstrap#python#find_python3_host() abort
    let l:index = 0
    let l:count = len(s:python3_candidates)
    let l:python3_host_prog = s:python3_candidates[l:index]
    while l:index < l:count
        let l:python3_host_prog = s:python3_candidates[l:index]
        if filereadable(l:python3_host_prog)
            return l:python3_host_prog
        endif
        let l:index = l:index + 1
    endwhile
    return ''
endfunction

function! bootstrap#python#setup() abort
    call bootstrap#python#setup_python3()
    call bootstrap#python#setup_python2()
endfunction

function! bootstrap#python#setup_python2() abort
    let g:python2_home = get(g:, "python2_home", "C:/Programs/Python/2.7.16-x64")
    if exists('g:python2_home')
        let &pythonhome = expand(g:python2_home)
    endif
    let g:python_dll = get(g:, "python_dll", "C:/Programs/Python/2.7.16-x64/libs/python27.dll")
    if filereadable(g:python_dll)
        let &pythondll = expand(g:python_dll)
    endif
    if has('python')
        return v:true
    else
        return v:false
    endif
endfunction

function! bootstrap#python#setup_python3() abort
    let g:python3_host_prog = bootstrap#python#find_python3_host()
    if empty(g:python3_host_prog)
        let g:python3_host_prog = '/home/xlchen/.venv/default/bin/python'
    endif
    call SpaceVim#logger#info('g:python3_host_prog = ' . g:python3_host_prog)
    if !empty(g:python3_host_prog)
        let &pythonthreehome = fnamemodify(g:python3_host_prog, ':p:h')
        let g:neomake_python_python_exe = g:python3_host_prog
    endif
    autocmd BufRead,BufNewFile *.py set filetype=python
    autocmd FileType python call s:on_python()
endfunction

function! s:on_python() abort
    setlocal foldmethod=indent
endfunction


